package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JdbcDemo1
{
    public static void main(String[] args) throws Exception
    {
        Class.forName("com.mysql.cj.jdbc.Driver");
        // mysql://localhost:3306/mysql?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
        String url  =  "jdbc:mysql://localhost:3340/tedu?useSSL=false&serverTimezone=UTC";
        String user = "root";
        String passWord = "wl249020...";
        Connection connection = DriverManager.getConnection(url, user, passWord);
        System.out.println("..//...///....///......");

        String sqlQuery = "select * from teacher";
        String createTableStatement = "create table userinfo(\n" +
                "    id int primary key  auto_increment,\n" +
                "    username varchar(30),\n" +
                "    password varchar(30),\n" +
                "    nickname varchar(30),\n" +
                "    age int(3)\n" +
                ");\n"   ;
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery(sqlQuery);
        while(resultSet.next())
        {
            String id = String.valueOf(resultSet.getInt("id"));
            String name = resultSet.getString("name");
            String age = String.valueOf(resultSet.getInt("age"));
            int subject_id = resultSet.getInt("subject_id");
            System.out.println("id = " + id + "  name =  " + name  + " age = " + age + " subject_id = " + subject_id
            );

        }
        statement.execute(createTableStatement  );
        System.out.println("create successfully");

    }
}
